package com.education.welco.controller;

import com.education.common.core.BaseController;
import com.education.common.pojo.SFlashClassTwo;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.SFlashClass;
import com.education.welco.service.ISFlashClassService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程虚拟教学 信息操作处理
 *
 * @author d
 * @date 2020-12-31
 */
@RestController
@RequestMapping("/sFlashClass")
public class SFlashClassController extends BaseController {

    @Autowired
    private ISFlashClassService sFlashClassService;

    /**
     * 查询课程虚拟教学列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(SFlashClass sFlashClass, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<SFlashClass> list = sFlashClassService.selectSFlashClassList(sFlashClass);
        PageInfo pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200", "查询成功", pageInfo);
    }

    /**
     * 查询课程虚拟教学列表
     */
    @GetMapping("/listOther")
    public List<SFlashClassTwo> listOther() {
        List<SFlashClass> list = sFlashClassService.selectSFlashClassList(null);
        List<SFlashClassTwo> list1 = Lists.newArrayList();
        for (SFlashClass sFlashClass : list) {
            SFlashClassTwo sFlashClass1 = new SFlashClassTwo();
            BeanUtils.copyProperties(sFlashClass, sFlashClass1);
            list1.add(sFlashClass1);
        }
        return list1;
    }


    /**
     * 新增保存课程虚拟教学
     */
    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody SFlashClass sFlashClass) {
        sFlashClassService.insertSFlashClass(sFlashClass);
        return new ApiReturnObject("200", "添加成功", "");
    }


    /**
     * 详情课程虚拟教学
     */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id) {
        SFlashClass result = sFlashClassService.selectSFlashClassById(id);
        return new ApiReturnObject("200", "查询成功", result);
    }

    /**
     * 修改保存课程虚拟教学
     */
    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody SFlashClass sFlashClass) {
        sFlashClassService.updateSFlashClass(sFlashClass);
        return new ApiReturnObject("200", "修改成功", "");
    }

    /**
     * 删除课程虚拟教学
     */
    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        sFlashClassService.deleteSFlashClassByIds(ids);
        return new ApiReturnObject("200", "删除成功", "");
    }
}